package com.formation.tocea.library.client.listener;

import com.formation.tocea.library.client.ui.form.LoginForm;
import com.formation.tocea.library.client.ui.main.Menu;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.RootPanel;

public class LoginSubmitListener implements ClickHandler {
	private LoginForm loginForm;

	public LoginSubmitListener(LoginForm loginForm) {
		this.loginForm = loginForm;
	}

	public void onClick(ClickEvent event) {
		String login = loginForm.getLoginTextBox().getValue();
		String password = loginForm.getPasswordTextBox().getValue();
		
		if (login.equals("armat") && password.equals("pass")) {
			Menu menu = (Menu) RootPanel.get("menu").getWidget(0);
			menu.setConnectedMode();
			loginForm.removeFromParent();			
		}
		else if (login == "" || password == "") {
			System.out.println("Veuillez remplir tous les champs");
		}
		else {
			System.out.println("Login ou mot de passe incorrect");
		}
	}
}
